package com.example.config;

import com.event.cache.iface.INamespaceCacheManager;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import java.util.Map;

/**
 * @Description
 * @Author Bing
 * @Date 2025/1/16 15:26
 */
public class CustomRedisCacheManager extends RedisCacheManager {

    private CustomRedisCacheWriter cacheWriter;

    private INamespaceCacheManager namespaceCacheManager;

    public CustomRedisCacheManager(RedisConnectionFactory connectionFactory, Map<String, RedisCacheConfiguration> initialCacheConfigurations,INamespaceCacheManager namespaceCacheManager) {
        super(new CustomRedisCacheWriter(connectionFactory), RedisCacheConfiguration.defaultCacheConfig(),initialCacheConfigurations);
        cacheWriter = new CustomRedisCacheWriter(connectionFactory);
        this.namespaceCacheManager = namespaceCacheManager;
    }

    @Override
    protected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {
        CustomRedisCache customRedisCache = new CustomRedisCache(namespaceCacheManager,name, cacheWriter, cacheConfig);
        return customRedisCache;
    }
}